package com.huangguolin.cloud.api.Catalogue.control;

import com.huangguolin.cloud.api.Catalogue.entity.ApiCatalogueSearchEntity;
import com.huangguolin.cloud.api.Catalogue.service.ApiCatalogueService;
import com.huangguolin.cloud.api.role.entity.ApiRoleSearchEntity;
import com.huangguolin.cloud.mybatis.entity.PtCatalogueEntity;
import com.huangguolin.cloud.mybatis.entity.PtRoleEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PagingEntity;
import com.huangguolin.cloud.mybatis.ztree.ChildTree;
import com.huangguolin.cloud.spring.control.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/catalogue")
public class ApiCatalogueController extends BaseController {
    @Resource
    private ApiCatalogueService apiCatalogueService;
    private Logger logger = LogManager.getLogger(this.getClass());


//    @RequestMapping("/queryCatalogueList")
//    public List<PtCatalogueEntity> queryCatalogueList(ApiCatalogueSearchEntity entity){
//        logger.info("entity:"+entity);
//      List<PtCatalogueEntity> list = apiCatalogueService.queryCatalogueList(entity);
//        return  list;
//    }
@RequestMapping("/queryCatalogueList")
public List<PtCatalogueEntity> queryCatalogueList(ApiCatalogueSearchEntity entity){

    List<PtCatalogueEntity> list = apiCatalogueService.queryCatalogueList(entity);
    return list;
}

    @RequestMapping("/queryMenuTree")
    public List<ChildTree> queryMenuTree(){
        List<ChildTree> list = apiCatalogueService.queryMenuTree();
        return list;
    }

    @RequestMapping("/queryCatalogueTotal")
    public String queryCatalogueTotal( ApiCatalogueSearchEntity entity){
        Integer total = apiCatalogueService.queryCatalogueTotal(entity);
        return  totalJSON(total);
    }

    //插入章节
    @RequestMapping("/insertChapter")
    public String insertChapter(String pid,String name,String sort){
        if(apiCatalogueService.insertChapter(pid,name,sort)){
            return failJSON("course.add.fail");
        }
        return successJSON("course.add.success");

    }

    //插入章
    @RequestMapping("/insert")
    public String insert(String pid,String name,String sort){
        if(apiCatalogueService.insert(pid,name,sort)){
            return failJSON("course.add.fail");
        }
        return successJSON("course.add.success");

    }


    //删除章节
    @RequestMapping("/delete")
    public String delete(@RequestParam("userUuids") String userUuids){
        if (userUuids == null){
            return failJSON("user.delete.fail");
        }
        apiCatalogueService.deleteUser(userUuids);
        return successJSON("user.delete.success");
    }

    //增加课程
    @RequestMapping("/addCourse")
    public String addCourse(String className,String picture,String classType,String radio,String courseIntroduction){
        if(apiCatalogueService.addCourse(className,picture,classType,radio,courseIntroduction)){
            return failJSON("user.delete.fail");
        }
        return successJSON("user.delete.success");
    }

    //修改课程
    @RequestMapping("/revise")
    public String revise(String id,String className,String picture,String classType,String radio,String courseIntroduction){
        if(apiCatalogueService.revise(id,className,picture,classType,radio,courseIntroduction)){
            return failJSON("user.delete.fail");
        }
        return successJSON("user.delete.success");
    }
}
